/**
 * 订单相关类型定义
 */

// 订单大类枚举
export enum OrderCategory {
  LAWSUIT = 1, // 诉讼订单
  LEGAL_SERVICE = 2, // 非诉订单
}

// 支付状态枚举
export enum PaymentStatus {
  UNPAID = 0, // 未支付
  PARTIAL = 1, // 部分支付
  PAID = 2, // 已支付
}

// 审核状态枚举
export enum ApprovalStatus {
  PENDING = 0, // 待审核
  PROCESSING = 1, // 审核中
  APPROVED = 2, // 审核通过
  REJECTED = 3, // 审核拒绝
}

// 交付状态枚举
export enum DeliveryStatus {
  PENDING = 0, // 待交付
  PROCESSING = 1, // 交付中
  COMPLETED = 2, // 已完成
}

// 订单主表接口
export interface Order {
  id: number
  order_no: string
  customer_id: number
  customer_name: string
  customer_type: number
  id_number?: string
  contact_id?: number
  contact_name?: string
  contact_phone?: string
  order_category: OrderCategory
  order_type: number
  order_type_name?: string
  related_order_id?: number
  contract_no?: string
  contract_amount: number
  post_amount: number
  total_amount: number
  paid_amount: number
  signer_id: number
  signer_name?: string
  contract_start_date?: number
  contract_end_date?: number
  contract_sign_date?: number
  contract_files?: FileInfo[]
  payment_status: PaymentStatus
  contract_archive_status: number
  approval_id?: number
  approval_status: ApprovalStatus
  delivery_status: DeliveryStatus
  department_id: number
  remark?: string
  lawsuitOrder?: LawsuitOrder
  legalServiceOrder?: LegalServiceOrder
  create_time: number
  update_time: number
}

// 诉讼订单详情接口
export interface LawsuitOrder {
  id: number
  order_id: number
  lawsuit_type: number // 1=案件委托，2=诉讼指导
  is_member_customer: number
  is_first_experience: number
  entrusting_party_identity: number // 1=原告，2=被告
  opposing_party_type: number
  opposing_party_name: string
  case_cause_id?: number
  case_cause_name?: string
  litigation_stage_category: number // 1=民商阶段，2=刑事阶段
  civil_stages?: string[]
  criminal_stages?: string[]
  case_amount_range: number
  case_amount_exact?: number
  litigation_request_elements?: string[]
  main_litigation_request?: string
  service_fee_pre?: number
  service_fee_post?: number
  create_time: number
  update_time: number
}

// 非诉订单详情接口
export interface LegalServiceOrder {
  id: number
  order_id: number
  service_category: number // 1=法律服务套餐，2=法律专项服务，3=常规法律服务
  package_type?: number // 1=普惠版，2=标准版，3=VIP版
  is_new_member: number
  account_type?: number // 1=主账号，2=子账号
  main_account_customer_id?: number
  sub_account_owner_type?: number
  has_first_experience: number
  lawsuit_guidance_quota: number
  lawsuit_guidance_used: number
  debt_collection_quota: number
  debt_collection_used: number
  legal_letter_count?: number
  contract_draft_count?: number
  contract_review_count?: number
  service_items?: any
  special_service_types?: string[]
  service_fee: number
  service_start_date?: number
  service_end_date?: number
  create_time: number
  update_time: number
}

// 支付记录接口
export interface OrderPayment {
  id: number
  order_id: number
  payment_item: number // 1=合同款，2=后期款
  payment_amount: number
  payment_method: number // 1=银行转账，2=支付宝，3=微信，4=现金，5=其他
  payment_date: number
  payment_proof_files?: FileInfo[]
  payer_name?: string
  receiver_account?: string
  verification_status: number // 0=未核实，1=已核实
  verifier_id?: number
  verification_time?: number
  remark?: string
  create_time: number
  update_time: number
}

// 订单类型接口
export interface OrderType {
  id: number
  category: OrderCategory
  type_code: string
  type_name: string
  description?: string
  sort_order: number
  status: number
  create_time: number
  update_time: number
}

// 文件信息接口
export interface FileInfo {
  file_name: string
  file_path: string
  file_size?: number
}

// 订单创建请求接口
export interface CreateOrderRequest {
  customer_id: number
  customer_type: number
  contact_id?: number
  order_category: OrderCategory
  order_type: number
  contract_no?: string
  contract_amount: number
  post_amount: number
  contract_start_date?: number
  contract_end_date?: number
  contract_sign_date?: number
  contract_files?: FileInfo[]
  payment_records?: OrderPayment[]
  lawsuit_detail?: Partial<LawsuitOrder>
  legal_service_detail?: Partial<LegalServiceOrder>
  remark?: string
}

// 订单列表查询参数
export interface OrderListQuery {
  page?: number
  limit?: number
  order_category?: OrderCategory
  order_type?: number
  approval_status?: ApprovalStatus
  payment_status?: PaymentStatus
  customer_name?: string
  order_no?: string
  start_date?: number
  end_date?: number
}

// 订单列表响应
export interface OrderListResponse {
  list: Order[]
  total: number
  page: number
  limit: number
}
